<%@ page session="true" buffer="16kb" import="java.sql.*,java.util.*,java.text.*"%>
<%@ page contentType="text/html; charset=utf-8" %>
<%
response.setDateHeader("Expires", 0); // date in the past
response.addHeader("Cache-Control", "no-store, no-cache, must-revalidate"); // HTTP/1.1 
response.addHeader("Cache-Control", "post-check=0, pre-check=0"); 
response.addHeader("Pragma", "no-cache"); // HTTP/1.0 
%>
<% Locale locale = Locale.getDefault();
locale = new Locale("zh","CN"); 
response.setLocale(locale);%>
<% session.setMaxInactiveInterval(30*60); %>
<% 
String login = (String) session.getAttribute("project1_status");
if (login == null || !login.equals("login")) {
response.sendRedirect("login.jsp");
response.flushBuffer(); 
return; 
}%>
<%int ewAllowAdmin = 16; 
int ewCurSec = 31;%>
<%@ include file="db.jsp" %>
<%@ include file="jspmkrfn.jsp" %>
<%
String tmpfld = null;
String escapeString = "\\\\'";
request.setCharacterEncoding("utf-8");
String key = request.getParameter("key");
if (key == null || key.length() == 0 ) {
	response.sendRedirect("order_infolist.jsp");
	response.flushBuffer();
	return;
}

// Get action
String a = request.getParameter("a");
if (a == null || a.length() == 0) {
	a = "I";	// Display with input box
}

// Get fields from form
Object x_ORDER_NUM = null;
Object x_COMPANY_NUM = null;
Object x_PRODUCTION_NUM = null;
Object x_PRICE = null;
Object x_QUANTITY = null;
Object x_ORDER_TIME = null;
Object x_ORDER_STATUS = null;
Object x_GROSS = null;

// Open Connection to the database
try{
	Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
	ResultSet rs = null;
	if (a.equals("I")){ // Get a record to display
		String tkey = "'" + key.replaceAll("'",escapeString) + "'";
		String strsql = "SELECT * FROM `order_info` WHERE `ORDER_NUM`=" + tkey;
		rs = stmt.executeQuery(strsql);
		if (!rs.next()) {
			rs.close();
			rs = null;
			stmt.close();
			stmt = null;
			conn.close();
			conn = null;
			out.clear();
			response.sendRedirect("order_infolist.jsp");
			response.flushBuffer();
			return;
		}else{
			rs.first();

			// Get the field contents
			if (rs.getString("ORDER_NUM") != null){
				x_ORDER_NUM = rs.getString("ORDER_NUM");
			}else{
				x_ORDER_NUM = "";
			}
			if (rs.getString("COMPANY_NUM") != null){
				x_COMPANY_NUM = rs.getString("COMPANY_NUM");
			}else{
				x_COMPANY_NUM = "";
			}
			if (rs.getString("PRODUCTION_NUM") != null){
				x_PRODUCTION_NUM = rs.getString("PRODUCTION_NUM");
			}else{
				x_PRODUCTION_NUM = "";
			}
	x_PRICE = String.valueOf(rs.getDouble("PRICE"));
	x_QUANTITY = String.valueOf(rs.getDouble("QUANTITY"));
			if (rs.getTimestamp("ORDER_TIME") != null){
				x_ORDER_TIME = rs.getTimestamp("ORDER_TIME");
			}else{
				x_ORDER_TIME = null;
			}
			if (rs.getString("ORDER_STATUS") != null){
				x_ORDER_STATUS = rs.getString("ORDER_STATUS");
			}else{
				x_ORDER_STATUS = "";
			}
	x_GROSS = String.valueOf(rs.getDouble("GROSS"));
		}
		rs.close();
	}else if (a.equals("U")) {// Update

		// Get fields from form
		if (request.getParameter("x_ORDER_NUM") != null){
			x_ORDER_NUM = (String) request.getParameter("x_ORDER_NUM");
		}else{
			x_ORDER_NUM = "";
		}
		if (request.getParameter("x_COMPANY_NUM") != null){
			x_COMPANY_NUM = (String) request.getParameter("x_COMPANY_NUM");
		}else{
			x_COMPANY_NUM = "";
		}
		if (request.getParameter("x_PRODUCTION_NUM") != null){
			x_PRODUCTION_NUM = (String) request.getParameter("x_PRODUCTION_NUM");
		}else{
			x_PRODUCTION_NUM = "";
		}
		if (request.getParameter("x_PRICE") != null){
			x_PRICE = (String) request.getParameter("x_PRICE");
		}else{
			x_PRICE = "";
		}
		if (request.getParameter("x_QUANTITY") != null){
			x_QUANTITY = (String) request.getParameter("x_QUANTITY");
		}else{
			x_QUANTITY = "";
		}
		if (request.getParameter("x_ORDER_TIME") != null){
			x_ORDER_TIME = (String) request.getParameter("x_ORDER_TIME");
		}else{
			x_ORDER_TIME = "";
		}
		if (request.getParameter("x_ORDER_STATUS") != null){
			x_ORDER_STATUS = (String) request.getParameter("x_ORDER_STATUS");
		}else{
			x_ORDER_STATUS = "";
		}
		if (request.getParameter("x_GROSS") != null){
			x_GROSS = (String) request.getParameter("x_GROSS");
		}else{
			x_GROSS = "";
		}

		// Open record
		String tkey = "'" + key.replaceAll("'",escapeString) + "'";
		String strsql = "SELECT * FROM `order_info` WHERE `ORDER_NUM`=" + tkey;
		rs = stmt.executeQuery(strsql);
		if (!rs.next()) {
			rs.close();
			rs = null;
			stmt.close();
			stmt = null;
			conn.close();
			conn = null;
			out.clear();
			response.sendRedirect("order_infolist.jsp");
			response.flushBuffer();
			return;
		}

		// Field ORDER_NUM
		tmpfld = ((String) x_ORDER_NUM);
		if (tmpfld == null || tmpfld.trim().length() == 0) {
			tmpfld = "";
		}
		if (tmpfld == null) {
			rs.updateNull("ORDER_NUM");
		}else{
			rs.updateString("ORDER_NUM", tmpfld);
		}

		// Field COMPANY_NUM
		tmpfld = ((String) x_COMPANY_NUM);
		if (tmpfld == null || tmpfld.trim().length() == 0) {
			tmpfld = "";
		}
		if (tmpfld == null) {
			rs.updateNull("COMPANY_NUM");
		}else{
			rs.updateString("COMPANY_NUM", tmpfld);
		}

		// Field PRODUCTION_NUM
		tmpfld = ((String) x_PRODUCTION_NUM);
		if (tmpfld == null || tmpfld.trim().length() == 0) {
			tmpfld = "";
		}
		if (tmpfld == null) {
			rs.updateNull("PRODUCTION_NUM");
		}else{
			rs.updateString("PRODUCTION_NUM", tmpfld);
		}

		// Field PRICE
		tmpfld = ((String) x_PRICE).trim();
		if (!IsNumeric(tmpfld)) {tmpfld = "0";}
		if (tmpfld != null) {
			rs.updateDouble("PRICE", Double.parseDouble(tmpfld));
		} else {
			rs.updateNull("PRICE");
		}

		// Field QUANTITY
		tmpfld = ((String) x_QUANTITY).trim();
		if (!IsNumeric(tmpfld)) {tmpfld = "0";}
		if (tmpfld != null) {
			rs.updateDouble("QUANTITY", Double.parseDouble(tmpfld));
		} else {
			rs.updateNull("QUANTITY");
		}

		// Field ORDER_TIME
		if (IsDate((String) x_ORDER_TIME,"DATE", locale)) {
			rs.updateTimestamp("ORDER_TIME", EW_UnFormatDateTime((String)x_ORDER_TIME,"DATE", locale));
		}else{
			rs.updateNull("ORDER_TIME");
		}

		// Field ORDER_STATUS
		tmpfld = ((String) x_ORDER_STATUS);
		if (tmpfld == null || tmpfld.trim().length() == 0) {
			tmpfld = null;
		}
		if (tmpfld == null) {
			rs.updateNull("ORDER_STATUS");
		}else{
			rs.updateString("ORDER_STATUS", tmpfld);
		}

		// Field GROSS
		tmpfld = ((String) x_GROSS).trim();
		if (!IsNumeric(tmpfld)) {tmpfld = null;}
		if (tmpfld != null) {
			rs.updateDouble("GROSS", Double.parseDouble(tmpfld));
		} else {
			rs.updateNull("GROSS");
		}
		rs.updateRow();
		rs.close();
		rs = null;
		stmt.close();
		stmt = null;
		conn.close();
		conn = null;
		response.sendRedirect("order_infolist.jsp");
		response.flushBuffer();
		return;
	}
}catch (SQLException ex){
		out.println(ex.toString());
}
%>
<%@ include file="header.jsp" %>
<div class="content">
	<div class="search">
		<p><span class="jspmaker table_name">订单信息编辑<br></span></p>
		<a class="jspmaker back" href="order_infolist.jsp">返回</a>
	</div>
	<script language="JavaScript" src="ew.js"></script>
	<script language="JavaScript">
	<!-- start Javascript
	function  EW_checkMyForm(EW_this) {
	if (EW_this.x_ORDER_NUM && !EW_hasValue(EW_this.x_ORDER_NUM, "TEXT" )) {
	            if (!EW_onError(EW_this, EW_this.x_ORDER_NUM, "TEXT", "Invalid Field - ORDER NUM"))
	                return false; 
	        }
	if (EW_this.x_COMPANY_NUM && !EW_hasValue(EW_this.x_COMPANY_NUM, "TEXT" )) {
	            if (!EW_onError(EW_this, EW_this.x_COMPANY_NUM, "TEXT", "Invalid Field - COMPANY NUM"))
	                return false; 
	        }
	if (EW_this.x_PRODUCTION_NUM && !EW_hasValue(EW_this.x_PRODUCTION_NUM, "TEXT" )) {
	            if (!EW_onError(EW_this, EW_this.x_PRODUCTION_NUM, "TEXT", "Invalid Field - PRODUCTION NUM"))
	                return false; 
	        }
	if (EW_this.x_PRICE && !EW_hasValue(EW_this.x_PRICE, "TEXT" )) {
	            if (!EW_onError(EW_this, EW_this.x_PRICE, "TEXT", "Incorrect floating point number - PRICE"))
	                return false; 
	        }
	if (EW_this.x_PRICE && !EW_checknumber(EW_this.x_PRICE.value)) {
	        if (!EW_onError(EW_this, EW_this.x_PRICE, "TEXT", "Incorrect floating point number - PRICE"))
	            return false; 
	        }
	if (EW_this.x_QUANTITY && !EW_hasValue(EW_this.x_QUANTITY, "TEXT" )) {
	            if (!EW_onError(EW_this, EW_this.x_QUANTITY, "TEXT", "Incorrect floating point number - QUANTITY"))
	                return false; 
	        }
	if (EW_this.x_QUANTITY && !EW_checknumber(EW_this.x_QUANTITY.value)) {
	        if (!EW_onError(EW_this, EW_this.x_QUANTITY, "TEXT", "Incorrect floating point number - QUANTITY"))
	            return false; 
	        }
	if (EW_this.x_ORDER_TIME && !EW_checkdate(EW_this.x_ORDER_TIME.value)) {
	        if (!EW_onError(EW_this, EW_this.x_ORDER_TIME, "TEXT", "Incorrect date (yyyy/mm/dd) - ORDER TIME"))
	            return false; 
	        }
	if (EW_this.x_GROSS && !EW_checknumber(EW_this.x_GROSS.value)) {
	        if (!EW_onError(EW_this, EW_this.x_GROSS, "TEXT", "Incorrect floating point number - GROSS"))
	            return false; 
	        }
	return true;
	}
	
	// end JavaScript -->
	</script>
	<form onSubmit="return EW_checkMyForm(this);"  name="order_infoedit" action="order_infoedit.jsp" method="post">
	<input type="hidden" name="a" value="U">
	<input type="hidden" name="key" value="<%= key %>">
	<table border="0" cellspacing="1" cellpadding="4" bgcolor="#CCCCCC">
		<tr>
			<td bgcolor="#594FBF"><span class="jspmaker" style="color: #FFFFFF;">订单编号</span>&nbsp;</td>
			<td bgcolor="#F5F5F5"><span class="jspmaker"><input type="text" name="x_ORDER_NUM" size="30" maxlength="20" value="<%= HTMLEncode((String)x_ORDER_NUM) %>"></span>&nbsp;</td>
		</tr>
		<tr>
			<td bgcolor="#594FBF"><span class="jspmaker" style="color: #FFFFFF;">企业编号</span>&nbsp;</td>
			<td bgcolor="#F5F5F5"><span class="jspmaker"><input type="text" name="x_COMPANY_NUM" size="30" maxlength="20" value="<%= HTMLEncode((String)x_COMPANY_NUM) %>"></span>&nbsp;</td>
		</tr>
		<tr>
			<td bgcolor="#594FBF"><span class="jspmaker" style="color: #FFFFFF;">商品编号</span>&nbsp;</td>
			<td bgcolor="#F5F5F5"><span class="jspmaker"><input type="text" name="x_PRODUCTION_NUM" size="30" maxlength="20" value="<%= HTMLEncode((String)x_PRODUCTION_NUM) %>"></span>&nbsp;</td>
		</tr>
		<tr>
			<td bgcolor="#594FBF"><span class="jspmaker" style="color: #FFFFFF;">价格</span>&nbsp;</td>
			<td bgcolor="#F5F5F5"><span class="jspmaker"><input type="text" name="x_PRICE" size="30" value="<%= HTMLEncode((String)x_PRICE) %>"></span>&nbsp;</td>
		</tr>
		<tr>
			<td bgcolor="#594FBF"><span class="jspmaker" style="color: #FFFFFF;">订货量</span>&nbsp;</td>
			<td bgcolor="#F5F5F5"><span class="jspmaker"><input type="text" name="x_QUANTITY" size="30" value="<%= HTMLEncode((String)x_QUANTITY) %>"></span>&nbsp;</td>
		</tr>
		<tr>
			<td bgcolor="#594FBF"><span class="jspmaker" style="color: #FFFFFF;">订货时间</span>&nbsp;</td>
			<td bgcolor="#F5F5F5"><span class="jspmaker"><input type="text" name="x_ORDER_TIME" value="<%= EW_FormatDateTime(x_ORDER_TIME,5, locale) %>"></span>&nbsp;</td>
		</tr>
		<tr>
			<td bgcolor="#594FBF"><span class="jspmaker" style="color: #FFFFFF;">订单状态</span>&nbsp;</td>
			<td bgcolor="#F5F5F5"><span class="jspmaker"><input type="text" name="x_ORDER_STATUS" size="30" maxlength="8" value="<%= HTMLEncode((String)x_ORDER_STATUS) %>"></span>&nbsp;</td>
		</tr>
		<tr>
			<td bgcolor="#594FBF"><span class="jspmaker" style="color: #FFFFFF;">订单总金额</span>&nbsp;</td>
			<td bgcolor="#F5F5F5"><span class="jspmaker"><input type="text" name="x_GROSS" size="30" value="<%= HTMLEncode((String)x_GROSS) %>"></span>&nbsp;</td>
		</tr>
	</table>
	<input class="editbutton" type="submit" name="Action" value="提交">
	</form>
</div>
<%@ include file="footer.jsp" %>
